<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/content/variable.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/content/head.jsp"%>
</head>
<body>
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">发送邮件</h3>
                </div>
                <form id="chlientAdd" class="form-horizontal" role="form">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="receiveEmail" class="col-sm-2 control-label">收件人邮箱：</label>
                            <div class="col-sm-8 ">
                                <input readonly="readonly" type="text" id="receiveEmail" class="form-control" 
                                       name="receiveEmail" value="${receiveEmail}">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="sendEmailUserName" class="col-sm-2 control-label">发件人邮箱：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="sendEmailUserName" class="form-control" 
                                		 name="sendEmailUserName"
                                		 readonly="readonly" value="${sendEmailUserName}">
                            </div>
                        </div>
                        <br>
                         <div class="form-group">
                            <label for="sendName" class="col-sm-2 control-label">发件人名称：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="sendName" class="form-control" name="sendName"
                                       placeholder="发件人名称">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="receiveName" class="col-sm-2 control-label">收件人名称：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="receiveName" class="form-control" name="receiveName"
                                       placeholder="收件人名称">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="emailTheme" class="col-sm-2 control-label">邮件主题：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="emailTheme" class="form-control" name="emailTheme"
                                       placeholder="邮件主题">
                            </div>
                        </div>
                       <br>
                       
                        <div class="form-group">
                            <label for="remark" class="col-sm-2 control-label">邮件正文：</label>
                            <div class="col-sm-8 ">
                                <textarea class="form-control" rows="3" class="form-control" placeholder="邮件正文..."
                                			id="emailContent" name="emailContent"></textarea>
                            </div>
                        </div>
                        <br>
                        
                      
                        <div class="col-md-offset-5 col-md-9">
                            <button type="submit" class="btn btn-success">确定</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
    <!-- /.row -->
<%@ include file="/content/js.jsp"%>
<script type="text/javascript">
	function selectUserId(){
		$.ajax({
			type:"post",
			url:"<%=path%>/user/findBusiness",
			dataType:"json",
			success: function(data){
				var optionstring = "";
				$.each(data.userList, function(i,val){
					 optionstring += "<option value=\"" + val.id + "\" >" + val.businessName + "</option>";
				});
				 $("#userId").html("<option value='-1'>请选择...</option> "+optionstring);  
			   }
			});
	}

    $(function () {
    	selectUserId();
        $('#chlientAdd').bootstrapValidator({
            message: '此值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
            	receiveName: {
                    message: '收件人名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '收件人名称不能为空'
                        },
                    }
                },
                emailTheme: {
                    message: '邮件主题验证失败',
                    validators: {
                        notEmpty: {
                            message: '邮件主题不能为空'
                        }
                    }
                },
                emailContent: {
                    message: '邮件正文验证失败',
                    validators: {
                        notEmpty: {
                            message: '邮件正文不能为空'
                        }
                    }
                },
                sendName: {
                    message: '发件人名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '发件人名称不能为空'
                        }
                    }
                },
            }
        }).on('success.form.bv', function (e) {//点击提交之后
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            save();
        });
    });

    function save() {
        $.post("<%=path%>/client/pushEmail",
            $("#chlientAdd").serialize()
            , function (data) {
                if (data.missage == "success") {
                    modalMsg("发送成功", "success");
                    window.parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }else{
                	 modalMsg("发送失败", "error");
                }

            }
        );
    }
    
</script>
</body>
</html>